<?php

class Connection {
    
    public static function getResult($query) {

        $link = mysql_connect("localhost","root","");

        if (!$link) {

            die('Could not connect: ' . mysql_error());

        }

        $db_selected = mysql_select_db('stark', $link);

        if (!$db_selected) {

            die ('Can\'t use Stark : ' . mysql_error());

        }

        $result = mysql_query($query);

        if (!$result) {

            $message  = 'Invalid query: ' . mysql_error() . "<br />";
            $message .= 'Whole query: ' . $query;
            die($message);

        } else {

            $data = Array();

            while ($row = mysql_fetch_assoc($result)) {
                array_push($data,$row);
            }

            mysql_close($link);

            return $data;

        }

    }

    public static function setValue($query) {

        $link = mysql_connect("localhost","root","");

        if (!$link) {

            die('Could not connect: ' . mysql_error());

        }

        $db_selected = mysql_select_db('stark', $link);

        if (!$db_selected) {

            die ('Can\'t use Stark : ' . mysql_error());

        }

        $query = utf8_decode($query);
        
        mysql_query($query);
        $id = mysql_insert_id();
                
        mysql_close($link);

        return $id;

    }

}

?> 
